package com.wl.dzt.ide.init;

import com.wl.dzt.basic.entity.BasicSql;
import com.wl.dzt.sys.core.dao.DB;
import com.wl.dzt.sys.core.dao.curd.sql.Sql;
import com.wl.dzt.sys.core.dao.select.Select;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/6/006
 * @description 脚本初始器
 */
@Order(10)
@Component
public class BasicSqlInit implements ApplicationRunner {


    /**
     * 载入数据库中的脚本进入内存
     *
     * @param args
     */
    @Override
    public void run(ApplicationArguments args) {
        List<BasicSql> list = DB.list(Select.create(BasicSql.class));
        list.forEach(sql -> Sql.ALL.put(sql.getSqlKey(), sql.getSqlSentence()));
    }
}
